package com.mushuilingfeng.ddd.user.infrastructure.cover;

import com.mushuilingfeng.ddd.user.domain.user.entity.User;
import com.mushuilingfeng.ddd.user.domain.user.entity.UserLoginDevice;
import com.mushuilingfeng.ddd.user.domain.user.vo.UserLoginLog;
import com.mushuilingfeng.ddd.user.domain.user.vo.UserPersonInfo;
import com.mushuilingfeng.ddd.user.infrastructure.repository.po.UserLoginDevicePO;
import com.mushuilingfeng.ddd.user.infrastructure.repository.po.UserLoginLogPO;
import com.mushuilingfeng.ddd.user.infrastructure.repository.po.UserPO;
import com.mushuilingfeng.ddd.user.infrastructure.repository.po.UserPersonInfoPO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author 沐水淋风
 * @date 2024/10/6
 */
@Mapper
public interface IPODataCover {
    IPODataCover INSTANCE = Mappers.getMapper(IPODataCover.class);
    
    @Mapping(source = "userPO", target = "loginAccount")
    @Mapping(source = "gender", target = "gender", ignore = true)
    @Mapping(source = "status", target = "status", ignore = true)
    User userPO2User(UserPO userPO);
    
    @Mapping(expression = "java(user.getGender().getCode())", target = "gender")
    @Mapping(expression = "java(user.getStatus().getCode())", target = "status")
    @Mapping(expression = "java(user.getLoginAccount().getLoginAccount())", target = "loginAccount")
    @Mapping(expression = "java(user.getLoginAccount().getLoginPassword())", target = "loginPassword")
    UserPO user2UserPO(User user);
    
    UserPersonInfoPO userPersonInfo2UserPersonInfoPO(UserPersonInfo userPersonInfo);
    
    UserPersonInfo userPersonInfoPO2UserPersonInfo(UserPersonInfoPO po);
    
    @Mapping(expression = "java(com.mushuilingfeng.ddd.user.domain.user.enums.LoginTypeEnum.get(po.getLoginType()))", target = "loginType")
    UserLoginLog userLoginLogPO2UserLoginLog(UserLoginLogPO po);
    
    @Mapping(expression = "java(log.getLoginType().getCode())", target = "loginType")
    UserLoginLogPO userLoginLog2UserLoginLogPO(UserLoginLog log);
    
    UserLoginDevice userLoginDevicePO2UserLoginDevice(UserLoginDevicePO po);
    
    List<UserLoginDevice> userLoginDevicePOList2UserLoginDeviceList(List<UserLoginDevicePO> poList);
    
    UserLoginDevicePO userLoginDevice2UserLoginDevicePO(UserLoginDevice device);
    
}
